#pragma once
#include<iostream>
#include<stdarg.h>
#include<string>
#include<strings.h>
using namespace std;


enum LogLevel
{
    DEBUG,   //0
    NORMAL,  //1
    WARNING, //2
    ERROR,   //3
    FATAL    //4
};

static const char* LevelString[] = {"DEBUG","NORMAL","WARNING","ERROR","FATAL"};  //日志的等级的字符串表示

// //最简单的日志函数，后续还会进行优化
// void logmessage(LogLevel level , string message)
// {
//     cout<<"["<<LevelString[level]<<"] : " << message <<endl;
// }

//可变参数版本
void logmessage(LogLevel level , const char* format , ...)
{
    char buffer[1024];
    bzero(buffer,sizeof buffer);
    va_list start;
    va_start(start,format);

    vsnprintf(buffer,sizeof buffer,format,start); //提取可变参数
    //再加上我们的日志等级的信息
    string logmsg = "[";
    logmsg += LevelString[level];
    logmsg += "] : ";
    logmsg+= buffer;
    cout<<logmsg<<endl;
}



